﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq;
using dhDataAcess.dataAcess.purchaseTableAdapters;
using dhDataAcess.dataAcess;

namespace dhDataAcess.produceDAL
{
   public  class productblDetailDAL
    {
        string  tableName = "productblDetail";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public productblDetailDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入领料出库主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productblDetailInsert(productblDetailModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
           // string insertstr = "insert into pbomMaster (mark,updateUser,updateDate,createUser,createDate,checkDate,spr,zbr,awgight,bweight,machineType,custNum,pname) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@checkDate,@spr,@zbr,@awgight,@bweight,@machineType,@custNum,@pname)";
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();

            SqlParameter[] para = {
                                       new SqlParameter ("@wb",row .wb  ),
                                        new SqlParameter ("@mark",row .mark ),
                                        new SqlParameter ("@createDate",row .createDate ),
                                        new SqlParameter ("@createUser",row .createUser ),
                                        new SqlParameter ("@stockqty",row .stockqty ),
                                        new SqlParameter ("@stockLength",row .stockLength),
                                        new SqlParameter ("@stockKg",row .stockKg ),
                                        new SqlParameter ("@gs",row .gs ),
                                        new SqlParameter ("@ts",row .ts ),
                                        new SqlParameter ("@pz",row .pz ),
                                        new SqlParameter ("@matName",row .matName ),
                                        new SqlParameter ("@matNum",row .matNum ),
                                        new SqlParameter ("@billNo",row .billNo ),
                                        new SqlParameter ("@pweight",row .pweight),
                                         new SqlParameter ("@oldts",row .oldts  ),
                                        new SqlParameter ("@oldgs",row .oldgs )
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新产品领料主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productblDetailUpdate(productblDetailModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            // string updatestr="update productList set mark=@mark,updateUser=@updateUser,updateDate=@updateDate,createUser=@createUser,createDate=@createDate,pattr=@pattr,pmode=@pmode,ptype=@ptype,pnameMark=@pnameMark,pname=@pname where recordid=@recordid";
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                        new SqlParameter ("@wb",row .wb  ),
                                        new SqlParameter ("@recordid",row .recordid  ),
                                        new SqlParameter ("@mark",row .mark ),
                                        new SqlParameter ("@createDate",row .createDate ),
                                        new SqlParameter ("@createUser",row .createUser ),
                                        new SqlParameter ("@stockqty",row .stockqty ),
                                        new SqlParameter ("@stockLength",row .stockLength),
                                        new SqlParameter ("@stockKg",row .stockKg ),
                                        new SqlParameter ("@gs",row .gs ),
                                        new SqlParameter ("@ts",row .ts ),
                                        new SqlParameter ("@pz",row .pz ),
                                        new SqlParameter ("@matName",row .matName ),
                                        new SqlParameter ("@matNum",row .matNum ),
                                        new SqlParameter ("@billNo",row .billNo ),
                                        new SqlParameter ("@pweight",row .pweight),
                                        new SqlParameter ("@oldts",row .oldts  ),
                                        new SqlParameter ("@oldgs",row .oldgs )
                                    };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行产品领料主表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int productblDetailDel(string recordid)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                
                                    new SqlParameter ("@recordid",recordid)
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
